package com.example.demo1.config;

import com.example.demo1.common.AppVariable;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.apache.ibatis.annotations.Insert;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 言初
 * Date: 2024-06-29
 * Time: 12:15
 */


// 用户登录拦截器


public class LoginIntercept implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession(false);
        if(session!=null && session.getAttribute(AppVariable.SESSION_USERINFO_KEY)!=null){
            //用户已登录
            return true;
        }

        //登录失败，跳转到登录页面
        response.sendRedirect("/login.html");
        return false;
    }
}















